<!DOCTYPE html>
<html>
<head>
#include("/admin/_common/head.html")
#include("/admin/_common/form_style.html")
<style type="text/css">
.layui-tab-content {background-color: #eee;}
.layui-tab-item {padding: 0 15px 0 15px;}
</style>
<title>设置</title>
</head>
<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-tab layui-tab-card" lay-filter="tab-utils">
                <ul class="layui-tab-title">
                    <li lay-id="site" class="layui-this">站点</li>
                    <li lay-id="company">公司</li>
                    <li lay-id="config">业务</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" lay-filter="site-option-form" onsubmit="return false;">
                            <div class="layui-card">
                            #shiroHasPermission('system:option:edit')
                                <div class="layui-card-header">
                                    <div class="layui-form-item layui-inline">
                                        <button class="pear-btn pear-btn-xs pear-btn-primary">
                                            <i class="pear-icon pear-icon-save"></i>&nbsp;保存站点设置
                                        </button>
                                    </div>
                                </div>
                            #end
                                <div class="layui-card-body">
                                    <div class="layui-row">
                                    #optionList(type='site', var='options')#for(item : options)
                                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                                            <div class="layui-form-item layui-block">
                                                <label class="layui-form-label">#(item.name)</label>
                                                <div class="layui-input-block">
                                                    <textarea name="site.#(item.key)" placeholder="#(item.remark)" class="layui-textarea">#(item.value)</textarea>
                                                    <div class="layui-form-mid layui-word-aux">#(item.remark)</div>
                                                </div>
                                            </div>
                                        </div>
                                    #end
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" lay-filter="company-option-form" onsubmit="return false;">
                            <div class="layui-card">
                            #shiroHasPermission('system:option:edit')
                                <div class="layui-card-header">
                                    <div class="layui-form-item layui-inline">
                                        <button class="pear-btn pear-btn-xs pear-btn-primary">
                                            <i class="pear-icon pear-icon-save"></i>&nbsp;保存公司设置
                                        </button>
                                    </div>
                                </div>
                            #end
                                <div class="layui-card-body">
                                    <div class="layui-row">
                                    #optionList(type='company', var='options')#for(item : options)
                                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                                            <div class="layui-form-item layui-block">
                                                <label class="layui-form-label">#(item.name)</label>
                                                <div class="layui-input-block">
                                                    <textarea name="company.#(item.key)" placeholder="#(item.remark)" class="layui-textarea">#(item.value)</textarea>
                                                    <div class="layui-form-mid layui-word-aux">#(item.remark)</div>
                                                </div>
                                            </div>
                                        </div>
                                    #end
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" lay-filter="config-option-form" onsubmit="return false;">
                            <div class="layui-card">
                            #shiroHasPermission('system:option:edit')
                                <div class="layui-card-header">
                                    <div class="layui-form-item layui-inline">
                                        <button class="pear-btn pear-btn-xs pear-btn-primary">
                                            <i class="pear-icon pear-icon-save"></i>&nbsp;保存业务设置
                                        </button>
                                    </div>
                                </div>
                            #end
                                <div class="layui-card-body">
                                    <div class="layui-row">
                                    #optionList(type='config', var='options')#for(item : options)
                                        <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                                            <div class="layui-form-item layui-block">
                                                <label class="layui-form-label">#(item.name)</label>
                                                <div class="layui-input-block">
                                                    <textarea name="config.#(item.key)" placeholder="#(item.remark)" class="layui-textarea">#(item.value)</textarea>
                                                    <div class="layui-form-mid layui-word-aux">#(item.remark)</div>
                                                </div>
                                            </div>
                                        </div>
                                    #end
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
#include("/admin/_common/foot.html")
<script type="text/javascript">
layui.use(['jquery', 'form', ], function() {
    var $ = layui.jquery;
    var form = layui.form;
    
    form.on('submit(site-option-form)', function() {
        var data = form.val("site-option-form");
        window.saveOption(data);
    });

    form.on('submit(company-option-form)', function() {
        var data = form.val("company-option-form");
        window.saveOption(data);
    });

    form.on('submit(config-option-form)', function() {
        var data = form.val("config-option-form");
        window.saveOption(data);
    });
    
    window.saveOption = function(data){
    	layer.confirm('确定要更新设置吗？', {
            icon: 3,
            title: '提示'
        }, function(index) {
            layer.close(index);
            var loading = layer.load();
            $.ajax({
                url: "#(ctxPath)/admin/system/option/save",
                dataType: 'json',
                type: 'put',
                data: data,
                success: function(result) {
                    layer.close(loading);
                    if (result.success) {
                        layer.msg('操作成功', {
                            icon: 1,
                            time: 1000
                        }, function() {
                        });
                    } else {
                        layer.alert(result.message);
                    }
                }
            })
        });
    }

});
</script>
</body>
</html>